const sequelize = require('../config/db')

async function getCategoryList(page, pageSize, where) {
  const [metadata] = await sequelize.query(`
       select categorys.id,
              categorys.name,
              categorys.description,
              categorys.image,
              categorys.status,
              categorys.createdAt,
              categorys.updatedAt,
              COUNT(posts.id) AS articleCount
       from categorys
                left join
            posts
            on
                categorys.id = posts.categoryId
           ${where}
       group by categorys.id
           limit ${page}, ${pageSize}
   `)
  return metadata
}
module.exports = {
  getCategoryList,
}
